/*
 * @Author: 大朱 243469235@qq.com
 * @Date: 2024-08-13 15:03:29
 * @LastEditors: 大朱 243469235@qq.com
 * @LastEditTime: 2024-08-14 16:55:27
 * @FilePath: \smart-electrical-box-nest\src\app\device\device.controller.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import {
  Get,
  Controller,
  Post,
  Req,
  Param,
  HttpStatus,
  UseGuards,
  Body,
  UsePipes,
  Query,
  Put,
} from '@nestjs/common';
import { DeviceService } from './device.service';
import { Roles } from '../../auth/roles.decorator';
import { RolesGuard } from '../../auth/roles.guard';
import { PgaeDto } from './device.dto';
import { Request, Response } from 'express';

@Controller('device')
export class DeviceController {
  constructor(private readonly deviceService: DeviceService) {}

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Post('create')
  create(@Body() param) {
    return this.deviceService.created(param);
  }

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Post('put/:id')
  put(@Param('id') id: string, @Body() param) {
    return this.deviceService.put(Number(id), param);
  }

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Post('delete')
  delete(@Body() param) {
    return this.deviceService.delete(param.id);
  }

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Get('getList')
  getList(@Query() query: PgaeDto) {
    return this.deviceService.getList(query);
  }

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Get('getUserList')
  getUserList(@Req() req: Request, @Query() query) {
    let userInfo = req['userInfo'];
    return this.deviceService.getUserList(
      userInfo.userId,
      query.type,
      query.status,
    );
  }

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Get('getInfo')
  getInfo(@Query('id') id: string) {
    return this.deviceService.getInfo(Number(id));
  }

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Get('getNumber')
  getNumber(@Req() req: Request) {
    let userInfo = req['userInfo'];
    return this.deviceService.getNumber(Number(userInfo.userId));
  }

  // @Roles('admin')
  // @UseGuards(RolesGuard)
  @Post('warn')
  warn(@Body() param) {
    return this.deviceService.warn(param.identifier, param.warnList);
  }

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Get('getPowerList')
  getPowerList(@Query() query: PgaeDto) {
    return this.deviceService.getPowerList(query);
  }

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Post('scanBindDevice')
  ScanBindDevice(@Req() req: Request, @Body() param) {
    let userInfo = req['userInfo'];
    return this.deviceService.ScanBindDevice(userInfo.userId, param);
  }

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Post('/updateGroup')
  updateGroup(@Body() body): Promise<object> {
    return this.deviceService.updateGroup(body);
  }
}
